packer.pyx 795 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from lakesuperior.cy_include cimport cytpl as tpl
  2. from libc.stdlib cimport malloc, free
  3. cdef:
  4. tpl.tpl_node *tn
  5. char *pack
  6. char *pack2
  7. size_t size
  8. size_t size2
  9. cdef struct URIRef:
  10. unsigned char *data
  11. cdef struct Literal:
  12. unsigned char type
  13. unsigned char *data
  14. unsigned char *datatype
  15. unsigned char *lang
  16. cdef Literal lit
  17. lit.type = 3
  18. lit.data = b'12345abcde'
  19. lit.datatype = b'xsd:string'
  20. lit.lang = b'en'
  21. tn = tpl.tpl_map("S(csss)", &lit)
  22. tpl.tpl_pack(tn, 0)
  23. tpl.tpl_dump(tn, tpl.TPL_MEM, &pack, &size)
  24. print(f'pack 1: {pack[: size]}')
  25. fmt = tpl.tpl_peek(tpl.TPL_MEM, pack, size)
  26. print(f'pack format: {fmt}')
  27. free(pack)
  28. tpl.tpl_free(tn)
  29. tpl.tpl_jot(tpl.TPL_MEM, &pack2, &size2, <unsigned char *>'S(csss)', &lit)
  30. print(pack2[:size2])
  31. free(pack2)