Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement nested objects and parsing?Examples are as follows #618

Open
kervin521 opened this issue Dec 31, 2021 · 0 comments
Open

Comments

@kervin521
Copy link

kervin521 commented Dec 31, 2021

public class MessagePackTest {
@Setter
	@Getter
	@NoArgsConstructor
	@AllArgsConstructor
	@ToString(callSuper = true)
	public static class HistoryValueView {
		private Long time;
		private Integer qos;
		private Object value;
		private transient Long diff;

	}
	@Setter
	@Getter
	@NoArgsConstructor
	@AllArgsConstructor
	@ToString(callSuper = true)
	public static class HistoryView {
		private String namespace;
		private String tag;
		private long total;
		private List<HistoryValueView> data;
	}
	public static void main(String[] args) throws IOException {
		List<HistoryView> list = Lists.newArrayList();
		HistoryView object = new HistoryView();
		object.setNamespace("unit05");
		object.setTag("A1.AV");
		object.setTotal(1);
		object.setData(Collections.singletonList(new HistoryValueView(Instant.now().toEpochMilli(), 1, 250.0, 0L)));
		MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
		packer.packArrayHeader(list.size());
.......
		packer.close();		
		MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(packer.toByteArray());
		ImmutableArrayValue array = unpacker.unpackValue().asArrayValue();
.......
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant