roc230 / spymemcached

Automatically exported from code.google.com/p/spymemcached
0 stars 0 forks source link

Unable to read Binary data (C Struct) from Memcache #314

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am using 2.10.4 on Linux Operating System.

  My Java project is reading C Structure from Memcache server. I am using Object net.spy.memcached.MemcachedClient.get(String key) function but not able to cast Object as byte[] array. This force me to use String then object serialization converting to byte array back but didn't find success.

  Is there any way to get value in byte[] array so that I can easily manipulate ? 

  Kindly provide solution for this.

Original issue reported on code.google.com by kathi...@gmail.com on 3 Dec 2014 at 6:52

GoogleCodeExporter commented 9 years ago
I think the easiest for you would be to create a custom transcoder. Just check 
the default implementation, implement the skeleton as a "pass through" and 
provide it to the get command. This will return you the byte[] directly as we 
take it from NIO.

Original comment by michael....@gmail.com on 3 Dec 2014 at 6:54

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks for your quick revert. I created one custom Transcode<byte[]> and passed 
it through get command. 

  I am getting following error.. 

java.lang.IllegalArgumentException: Cannot cache data larger than 0 bytes (you 
tried to cache a 4 byte object)
    at net.spy.memcached.CachedData.<init>(CachedData.java:55)
    at net.spy.memcached.MemcachedClient$5.gotData(MemcachedClient.java:1031)
    at net.spy.memcached.protocol.ascii.BaseGetOpImpl.handleRead(BaseGetOpImpl.java:147)
    at net.spy.memcached.protocol.ascii.OperationImpl.readFromBuffer(OperationImpl.java:129)
    at net.spy.memcached.MemcachedConnection.readBufferAndLogMetrics(MemcachedConnection.java:813)
    at net.spy.memcached.MemcachedConnection.handleReads(MemcachedConnection.java:792)
    at net.spy.memcached.MemcachedConnection.handleReadsAndWrites(MemcachedConnection.java:672)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:635)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:409

 Could you please point to some examples for implementation.

Original comment by kathi...@gmail.com on 3 Dec 2014 at 7:35

GoogleCodeExporter commented 9 years ago
Just for the sake of decoding maybe try: 
https://gist.github.com/daschl/ef05c435c36ef1dfdb5c

Original comment by michael....@gmail.com on 3 Dec 2014 at 7:50

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks Working fine.

Original comment by kathi...@gmail.com on 4 Dec 2014 at 5:43

GoogleCodeExporter commented 9 years ago
Cheers! If you want to write data just implement this one also as a passthrough

Original comment by michael....@gmail.com on 4 Dec 2014 at 6:15